<?php

namespace App\Console\Commands;

use App\Jobs\FileJob;
use App\Services\FileService;
use Illuminate\Console\Command;
use App\Service\GitService;
use App\Service\ElasticSearchService;
use Elasticsearch\ClientBuilder;
use Illuminate\Support\Facades\DB;
use Grafika\Grafika;

class zhang extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'zhang';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        echo dirname('./aa.jpg');exit;
        return self::resize_img();
        // self::test_git();
        // self::test_search();
        // self::test_git_init();
        $files = scan_files(config('git.root'));
        print_r($files);
        return 0;
    }

    private static function test_git() {
        $path = "zhang-C-Users-Administrator-Desktop-商机";
        // $path   = "E:\phpstudy_pro\WWW\shidao-DMS\desk-client";
        $git    = new GitService($path);
        $files  = $git->getChangedFiles();
        print_r($files);
    }

    private static function test_git_init() {
        $name = "demo2";
        $git = new GitService($name);
        $git->createRepository();
    }

    private static function test_search() {

        // $client = ClientBuilder::create()->build();
        // dd($client);
        // $search = new ElasticSearchService();
        // $search->get(1);
        // $search->search(['match' => ['address' => '上海贵州']]);
        $files = FileService::search('教导模式');
        print_r($files);
    }

    private static function resize_img() {
        $editor = Grafika::createEditor();
        $path = 'E:\phpstudy_pro\WWW\shidao-DMS\backend\public\upload\6d461abb09caa51a090a015b924065ae.jpg';
        $editor->open($img, $path);
        $editor->resizeExactWidth($img, 200);
        $editor->save($img, $path.'thumb.jpg');
    }
}
